# Contriburo: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Michael Mason <ms13sp@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnutls
pkgver=3.8.1
pkgrel=0
pkgdesc="TLS protocol implementation"
url="https://www.gnutls.org/"
arch="all"
license="LGPL-2.1-or-later"
checkdepends="diffutils datefudge"
makedepends="
	libidn2-dev
	libkcapi-dev
	libtasn1-dev
	libunistring-dev
	linux-headers
	nettle-dev
	p11-kit-dev
	texinfo
	zlib-dev
	"
subpackages="$pkgname-dbg $pkgname-doc $pkgname-dev $pkgname-utils $pkgname-c++:xx"
_v=${pkgver%.*}
case $pkgver in
*.*.*.*) _v=${_v%.*};;
esac
source="https://www.gnupg.org/ftp/gcrypt/gnutls/v$_v/gnutls-$pkgver.tar.xz
	skip-crq.patch
	skip-ktls.patch
	tests-certtool.patch
	"

# Upstream Tracker: https://gnutls.org/security-new.html
# secfixes:
#   3.8.0-r0:
#     - CVE-2023-0361
#   3.7.7-r0:
#     - CVE-2022-2509 GNUTLS-SA-2022-07-07
#   3.7.1-r0:
#     - CVE-2021-20231 GNUTLS-SA-2021-03-10
#     - CVE-2021-20232 GNUTLS-SA-2021-03-10
#   3.6.15-r0:
#     - CVE-2020-24659 GNUTLS-SA-2020-09-04
#   3.6.14-r0:
#     - CVE-2020-13777 GNUTLS-SA-2020-06-03
#   3.6.13-r0:
#     - CVE-2020-11501 GNUTLS-SA-2020-03-31
#   3.6.7-r0:
#     - CVE-2019-3836
#     - CVE-2019-3829
#   3.5.13-r0:
#     - CVE-2017-7507

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-ktls \
		--disable-openssl-compatibility \
		--disable-rpath \
		--disable-static \
		--disable-valgrind-tests
	make
}

check() {
	# millis, 100s
	export GNUTLS_TEST_TIMEOUT=100000
	make check 	|| {
		cat tests/test-suite.log
		return 1
	}
}

package() {
	DESTDIR="$pkgdir" make -C "$builddir" install
}

utils() {
	license="GPL-3.0-or-later"
	pkgdesc="Command line tools for TLS protocol"
	mkdir -p "$subpkgdir"/usr/
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

xx() {
	pkgdesc="The C++ interface to GnuTLS"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/lib*xx.so.* "$subpkgdir"/usr/lib/
}

sha512sums="
22e78db86b835843df897d14ad633d8a553c0f9b1389daa0c2f864869c6b9ca889028d434f9552237dc4f1b37c978fbe0cce166e3768e5d4e8850ff69a6fc872  gnutls-3.8.1.tar.xz
de90c00958e930dec65f90e0d494df248016bfa924f65c08e0c84f36ae61ad2d4c7bf9bb2cf7ac652055bdadcdb54d94a79ca929aa6f85e5fe3bb1e7deb33f64  skip-crq.patch
58bb2e6cc2c25a2884440d04383dd4fbaacc5e55d0cb584bcd219fb99e9b23cbf9524cc888a6f3c17fd70ecbd0c81e2f39b3dd3457eb8d3824fed50092d1d8a1  skip-ktls.patch
2006876dd33559a9ee4abe73e7cedc6867c4f480befdfd5fe9e3eca327e291c3cdb12385156c2ba5ab9496dec870b15178249e015363397f1d979ef785906366  tests-certtool.patch
"
